package com.binhai.org;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 72645
 * @description 针对表【t_org】的数据库操作Service实现
 * @createDate 2025-05-08 08:55:14
 */
@Service
public class OrgBeanServiceImpl extends ServiceImpl<OrgBeanMapper, OrgBean>
{
    @Autowired
    private OrgBeanMapper orgBeanMapper;
    public List<OrgBean> selectAllInfos() {
        //查询是有条件的，parentid不等于0
//             QueryWrapper<OrgBean> orgBeanQueryWrapper = new QueryWrapper<>();
//             orgBeanQueryWrapper.ne("parentid",0);
//             return orgBeanMapper.selectList(orgBeanQueryWrapper);
        return orgBeanMapper.selectAllInfos();
    }

    public List<OrgBean> selectOrgTree() {
        return orgBeanMapper.selectOrgTree();
    }

    public Map saveOrUpdateInfo(OrgBean orgBean) {
        Map map =new HashMap();
        try {
            if (orgBean.getId()==null||orgBean.getId()==0)
            {
                orgBeanMapper.insert(orgBean);

            }else {
                orgBeanMapper.updateById(orgBean);
            }
            map.put("result", "success");
        }catch (Exception e){
            e.printStackTrace();
            map.put("result","error");
        }
        return map;
    }
    public OrgBean getInfoById(int id) {
        return orgBeanMapper.selectById(id);
    }

    public Map deleteInfo(int id) {
        Map map = new HashMap();
        try {
            //根据id删除数据
            orgBeanMapper.deleteById(id);
            map.put("result","success");
            return map;
        }
        catch (Exception e){
            e.printStackTrace();
            map.put("result","error");
            return map;
        }
    }
}




